#include "widget.h"
#include "ui_widget.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    initUi();
}

Widget::~Widget()
{
    delete ui;
}


void Widget::initUi()
{
    // 设置窗口背景透明
    setWindowFlag(Qt::WindowType::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    // 给窗口设置阴影效果
    QGraphicsDropShadowEffect* shadowEffect = new QGraphicsDropShadowEffect(this);
    shadowEffect->setOffset(0,0); // 设置阴影偏移
    shadowEffect->setColor("#000000"); // 设置阴影颜色：黑色
    shadowEffect->setBlurRadius(20); // 设置阴影的模糊半径
    this->setGraphicsEffect(shadowEffect);
}


void Widget::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        //isDrag = true;
        // 获取鼠标相对于电脑屏幕左上角的全局坐标
        dragPos = event->globalPos() - geometry().topLeft();
        return;
    }

    QWidget::mousePressEvent(event);

}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    if(event->buttons() == Qt::LeftButton )// QPoint  dragPos;

    {
        move(event->globalPos() - dragPos);

        //qDebug()<<"mouse move";
        return;
    }

    QWidget::mouseMoveEvent(event);
}


void Widget::on_quit_clicked()
{
    this->close();
}

